package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.StoreLocationDto;
import com.wms.entity.StoreLocation;
import com.wms.exception.V;
import com.wms.service.StoreLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "csy货位管理")
@RequestMapping("/api")
public class StoreLocationController {
    @Autowired
    StoreLocationService storeLocationService;

    @PostMapping("/location/list")
    @ApiOperation(value = "获取货位列表信息")
    public ResultBean getAll(@RequestBody StoreLocationDto storeLocationDto){
            PageBean pageBean=storeLocationService.queryList(storeLocationDto);
            return R.success("货位管理列表",pageBean);
    }

    @PostMapping("/location/add")
    @ApiOperation(value = "添加货位")
    public ResultBean add(@RequestBody StoreLocation storeLocation, BindingResult result){
        V.validate(result);
        int n=storeLocationService.addStoreLocation(storeLocation);
        return n==1?R.success("添加成功"):R.fail("添加失败");
    }

    @DeleteMapping("/location/deleteById")
    @ApiOperation(value = "根据id删除")
    public ResultBean deleteById(@RequestParam int id){
        int n=storeLocationService.removeById(id);
        return n==1?R.success("删除成功"):R.fail("删除失败");
    }

    @PutMapping("/location/change")
    @ApiOperation(value = "修改操作")
    public ResultBean change(@RequestParam int id,@RequestBody StoreLocation storeLocation){
        storeLocation.setId(id);
        int n=storeLocationService.changeStoreLocation(storeLocation);
        return n==1?R.success("修改成功"):R.fail("修改失败");
    }

    @DeleteMapping("/location/deleteSome")
    @ApiOperation(value = "批量删除")
    public ResultBean removeSome(@RequestBody List<Integer> ids){
        int n=storeLocationService.deleteSome(ids);
        return n>0?R.success("删除成功"):R.fail("删除失败");
    }


}
